Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added connect.timeout() middleware #519

Closed
wants to merge 16 commits into from

Conversation

hunterloftis
Copy link

Timeout tests included. All tests pass.

re: #499

@tj
Copy link
Member

tj commented Mar 29, 2012

cool thanks! I'll tweak a few little things and merge it over

at = req.method + ' ' + req.url,
timer = setTimeout(function() {
if (options.throwError) {
return next(new Error('Timeout ' + req.method + ' ' + req.url));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this actually doesn't work as expected, I'll see if I can find a work-around

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious about how that was expected to work; I just duplicated the old connect-timeout stuff.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sort of use-case will work better with #522

I need to think on that some more though, both have pros/cons, deferred errors like this one might invoke app.error several times which is good for reporting but bad for responding. we could tell people to check if (res.headerSent) but that's kinda lame, almost need one callback for reporting errors and one for responding :s but that's sorta lame too

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way a timeout should occur is if res.end() is not called within a preset amount of time. This means that there can only be one timeout error. This deferred error can only happen once at most. IMHO, this behavior is desired.

Say an error occurs (i.e. next(err) is called)... the error handler can decide whether or not to call next() or do res.send(500); or whatever. Maybe the error handler prints the message to stderr, or maybe an email is sent. If the error handler decides to call res.send(), then technically, no timeout has happened. So, there is only one error reported to the client. Similarly, only one timeout error can happen.

@bminer
Copy link
Contributor

bminer commented May 24, 2012

It would also be cool to change the timeout on a per-request basis. Using req.setTimeout(5000) or whatever to clear the current timer and set the new timeout to 5 seconds. This might be cool in case you are doing a large operation, but you have access to the progress of the operation. Or, maybe, different operations might require more time.

I'd also suggest proxying the res.end function instead of res.writeHead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants